package com.tech.platform.cms.logger.publish;

import cn.hutool.system.SystemUtil;
import com.tech.platform.cms.logger.annotation.ErrorLog;
import com.tech.platform.cms.logger.event.ErrorLogEvent;
import com.tech.platform.cms.logger.model.ErrorLogModel;
import com.tech.platform.cms.logger.utils.SpringEventUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author shengqiang.wu
 * @date 2020/3/26/026 17:54
 * @desc
 */
@Component
public class ErrorLogPublish {

    public void publish(ErrorLog errorLog, Throwable ex){

        String moduleName = errorLog.title();
        String errorMessage = ex.getMessage();

        String hostIp = SystemUtil.getHostInfo().getAddress();
        String className = "";
        String methodName = "";

        ErrorLogModel model = new ErrorLogModel();
        model.setModelName(moduleName);
        model.setErrorMessage(errorMessage);
        model.setClassName(className);
        model.setHost(hostIp);
        model.setMethod(methodName);
        model.setCreateTime(new Date());
        SpringEventUtils.publishEvent(new ErrorLogEvent(model));
    }
}
